package com.plane.ticketse.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.plane.ticketse.utils.Result;
import com.plane.ticketse.utils.Time;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.plane.ticketse.service.ITicketService;
import com.plane.ticketse.entity.Ticket;

import org.springframework.web.bind.annotation.RestController;

/**
 * TicketController 前端控制器
 * @author 作者
 * @since 2023-12-25
 */
@RestController
@RequestMapping("/ticket")
public class TicketController {

    @Resource
    private ITicketService ticketService;

    /**
    *  新增或者更新
    */
    @PostMapping("/edit")
    public Result save(@RequestBody Ticket ticket) {
        if (ticket.getId()==null){
            ticket.setFlightNo(Time.getTimeStamp());
        }
        return Result.success(ticketService.saveOrUpdate(ticket));
    }
    /**
    *  删除
    */
    @GetMapping("delete/{id}")
    public Result delete(@PathVariable Integer id) {
        return Result.success(ticketService.removeById(id));
    }
    /**
    *  查询所有
    */
    @GetMapping("/all")
    public Result findAll() {
        QueryWrapper<Ticket> queryWrapper = new QueryWrapper<>();
       List<Ticket> list=  ticketService.list(queryWrapper);
        return Result.success(list);
    }
    /**
    *  根据id查询
    */
    @GetMapping("/{id}")
    public Result findOne(@PathVariable Integer id) {
        return Result.success(ticketService.getById(id));
    }

}

